home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / c / cenvid9.zip / PRIMES.BAT < prev    next >
DOS Batch File  |  1994-03-04  |  841b  |  27 lines

  1. @echo off
  2. REM **********************************************************************
  3. REM *** Primes.bat - Print out prime numbers until a key is pressed or ***
  4. REM *** ver.1        we run out of memory or overflow                  ***
  5. REM **********************************************************************
  6.  
  7. cenvi %0.bat
  8. GOTO CENVI_EXIT
  9.  
  10. printf("Printing prime numbers until a key pressed (or failure):\n")
  11.  
  12. for ( Count = 0, Try = 2; !kbhit(); Try++ ) {
  13.    // check if this is divisible by any of the primes found so far
  14.    for ( i = 0; i < Count; i++ )
  15.       if !(Try % Prime[i])
  16.          break
  17.    if ( i == Count )
  18.       // this new prime number was found, and so add to the list and print it
  19.       printf("%d\t",Prime[Count++]=Try)
  20. }
  21. // flush the keyboard
  22. while( kbhit() ) getch()
  23.  
  24. printf("\n")
  25.  
  26. :CENVI_EXIT
  27.